package resource.proxy;

import resource.DoPrint;
import resource.ExtendPrint;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyDo{


    public static <T>T getProxy(Class<T> t) {
        T proxyInstance = (T)Proxy.newProxyInstance(t.getClassLoader(), t.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(method.getName());
                System.out.println("增强");
                method.invoke(t.newInstance(),args);
                return null;
            }
        });

        return proxyInstance;
    }
}
